<template>
	<view class="page_view">
		<view class="top_view flex1">
			<view class="top_view_left">提现至</view>
			<view class="top_view_right flex1" @click="choose_zhanghu">
				<image :src="list_active.Image" class="top_view_right_img" mode=""></image>
				<view class="top_view_right_text">{{list_active.name}}</view>
			</view>
		</view>
		<view class="min_view">
			<view class="min_view_title">提现金额</view>
			<view class="min_view_input flex">
				<view class="min_view_input_ivon">¥</view>
				<input type="digit" class="min_view_input_ivon_input" placeholder="请输入" placeholder-style="color: #999;"
					v-model="money" />
			</view>
			<!-- -->
			<view v-if="money" class="shouxu">
				手续费￥{{(money*config.value/100).toFixed(2)}}，费率{{config.value}}%
			</view>
			<view class="desc">
				可提现余额¥{{balance}}，
				<text style="color: #0165fb">全部提现</text>
			</view>
		</view>
		<!-- <view class="" v-if="type_index == 0">
			<view class="min_view_title">微信收款码</view>
			<view class="wx_img" @click="choose_img"> 
				<image src="https://bucketoss10086.oss-cn-beijing.aliyuncs.com/miniprogram/upload.png"  class="wx_img_add" mode="" v-if="!wx_img"></image>
				<image :src="ImgUrl + wx_img" class="wx_img_ma" mode="" v-else></image>
			</view>
		</view> -->
		<view class="" v-if="type_index == 1">
			<view class="min_view_title">支付宝</view>
			<input type="text" placeholder="请输入支付宝账号" class="apli_input" v-model="alipay_account" />
		</view>
		<view class="" v-if="type_index == 2">
			<view class="min_view_title">银行卡</view>
			<input type="text" placeholder="请输入银行卡账号" class="apli_input" v-model="yinhangkanum" />
			<!-- <input type="text" placeholder="请输入身份证号码" class="apli_input" v-model="idnum" /> -->
		</view>
		<!-- <input type="text" placeholder="您的真实姓名" class="apli_input" v-model="truename"/> -->
		<view class="btn" @click="go_Examine">确定</view>
		<view class="rul" v-html="config2.value">
			<!-- <rich-text :nodes="config."></rich-text> -->
			<!-- {{}} -->
		</view>
		<view class="xieyi_view">
			<checkbox-group @change="change">
				<label>
					<checkbox value="2" :checked="checked == 2 ? true : false" color="#6E8CFA"
						style="transform: scale(0.7)" />
					<text class="text_5">
						遵守并同意
						<text class="xieyi" @tap.stop="xieyi(3)">《灵活就业合作伙伴协议》</text>
						<!-- <text class="xieyi" @tap.stop="xieyi()">{{title}}</text> -->
					</text>
				</label>
			</checkbox-group>
		</view>
	</view>
</template>

<script>
	import {
		withdrawhandle,
		config,
		withdrawUrl,
		withdrawSign,
	} from '@/api/common.js'
	import uploadImage from '@/common/ossutil/uploadFile.js';
	export default {
		data() {
			return {
				money: '',
				list: [{
						name: '微信账户',
						Image: 'https://bucketoss10086.oss-cn-beijing.aliyuncs.com/miniprogram/wx_img.png'
					},
					{
						name: '支付宝账户',
						Image: 'https://bucketoss10086.oss-cn-beijing.aliyuncs.com/miniprogram/wx_img.png'
					},
					{
						name: '银行卡账户',
						Image: 'https://bucketoss10086.oss-cn-beijing.aliyuncs.com/miniprogram/wx_img.png'
					}

				],
				balance: '',
				wx_img: '',
				ImgUrl: this.$ImgUrl,
				list_active: {
					name: '微信账户',
					Image: 'https://bucketoss10086.oss-cn-beijing.aliyuncs.com/miniprogram/wx_img.png'
				},
				truename: '',
				alipay_account: '',
				yinhangkanum: '',
				idnum: '',
				type_index: 0,
				config: '',
				config2: '',
				config3: '',
				yzh_sign_status:0,
				title:'',
				url2:'',
			};
		},
		onLoad(options) {
			this.yzh_sign_status = options.yzh_sign_status;
			withdrawUrl().then(res=>{
				this.url2 = res.data.url;
				this.title = res.data.title;
			})
			if (options.balance) {
				this.balance = options.balance
			}
			this.getconfig();
			let t = this;
			config({
				key: 'withdraw_desc'
			}).then(res => {
				console.log(res)
				if (res.code == 200001) {
					t.config2 = res.data[0]
				}
			})
			config({
				key: 'withdraw_limit'
			}).then(res => {
				console.log(res)
				if (res.code == 200001) {
					t.config3 = res.data[0]
				}
			})
		},
		methods: {
			xieyi(){
				uni.setStorageSync('webviewSrc',this.url2);
				uni.navigateTo({
					url: '/pages/webview/webview'
				})
			},
			xieyi(type) {
				uni.navigateTo({
					url: '/pages/xieyi/xieyi?type=' + type
				})
			},
			getconfig() {
				let t = this
				config({
					key: 'withdraw_commission'
				}).then(res => {
					console.log(res)
					if (res.code == 200001) {
						t.config = res.data[0]
					}
				})
			},
			choose_zhanghu() {
				let t = this
				uni.showActionSheet({
					itemList: ['微信账户', '支付宝账户', '银行卡'],
					success(res) {
						t.type_index = res.tapIndex
						t.list_active = t.list[res.tapIndex]
					},
					fail(res) {
						console.log(res.errMsg)
					}
				})

			},
			choose_img() {
				let that = this
				uni.chooseImage({
					count: 1,
					success(res) {
						let path = res.tempFilePaths[0]
						uploadImage(path, '', 'wechat/', (res) => {
							console.log(res);
							that.wx_img = res.imgName;
						});
					}
				})
			},
			async go_Examine() {
				if(this.yzh_sign_status==0){
					let res = await withdrawSign();
					this.yzh_sign_status = 1;
					this.go_Examine1();
				}else{
					this.go_Examine1();
				}
			},
			go_Examine1() {
				let t = this
				if (Number(t.money) >= Number(t.config3.value)) {
					withdrawhandle({
						type: 2,
						channel: t.type_index == 0 ? '2' : t.type_index == 1 ? '1' : t.type_index == 2 ? '3' : '',
						wechat_image: t.wx_img,
						alipay_account: t.alipay_account,
						truename: t.truename,
						amount: t.money,
						card_number: t.yinhangkanum,
						id_number: t.idnum
					}).then(res => {
						if (res.code == 200001) {
							uni.showToast({
								title: '提现已提交',
								icon: 'none'
							})
							setTimeout(() => {
								uni.navigateTo({
									url: '/pages/Examine/Examine?money=' + t.money
								})
							}, 1500)
						} else {
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
						}

					})
				} else {
					uni.showToast({
						title: '满'+t.config3.value+'元可提现哦',
						icon: 'none'
					})
				}


			},
		}
	};
</script>

<style>
	.xieyi_view {
		position: fixed;
		bottom: 50rpx;
		width: 680rpx;
		left: 75rpx;
		font-family: 'Alibaba PuHuiTi 2.0';
		font-style: normal;
		font-weight: 400;
		font-size: 28rpx;
		color: #a1afb3;
	}

	page {
		background: #fff;
	}

	.page_view {
		width: 100%;
		padding: 0 30rpx;
		box-sizing: border-box;
	}

	.top_view {
		width: 100%;
		height: 100rpx;
		border-bottom: 1rpx solid #f4f4f4;
	}

	.top_view_left {
		color: #161616;
		font-family: Alibaba PuHuiTi 2;
		font-size: 26rpx;
		font-weight: 400;
	}

	.top_view_right {
		width: calc(100% - 100rpx);
		justify-content: center;
	}

	.top_view_right_text {
		color: #999;
		font-family: Alibaba PuHuiTi 2;
		font-size: 26rpx;
		font-weight: 400;
	}

	.top_view_right_img {
		width: 36rpx;
		height: 36rpx;
	}

	.top_view_right_text {
		color: #999;
		font-family: Alibaba PuHuiTi 2;
		font-size: 26rpx;
		font-weight: 400;
		margin-left: 14rpx;
	}

	.min_view_title {
		color: #161616;
		font-family: Alibaba PuHuiTi 2;
		font-size: 26rpx;
		font-weight: 400;
		margin-top: 32rpx;
	}

	.min_view_input_ivon {
		color: #161616;
		text-align: center;
		font-family: Alibaba PuHuiTi 2;
		font-size: 48rpx;
		font-weight: 400;
	}

	.min_view_input {
		width: 100%;
		padding: 32rpx 0;
		box-sizing: border-box;
		border-bottom: 1rpx solid #f4f4f4;
	}

	.min_view_input_ivon_input {
		width: calc(100% - 50rpx);
		color: #161616;
		font-family: Alibaba PuHuiTi 2;
		font-size: 64rpx;
		font-weight: 400;
		height: 80rpx;
	}

	.desc {
		color: #999;
		font-family: Alibaba PuHuiTi 2;
		font-size: 24rpx;
		font-style: normal;
		font-weight: 400;
		line-height: normal;
		margin-top: 32rpx;
	}

	.btn {
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		border-radius: 68rpx;
		background: #0165fb;
		color: #fff;
		font-family: Alibaba PuHuiTi 2;
		font-size: 30rpx;
		font-weight: 400;
		margin-top: 48rpx;
	}

	.rul {
		color: #999;
		font-family: Alibaba PuHuiTi 2;
		font-size: 24rpx;
		font-weight: 400;
		margin-top: 32rpx;
	}

	.shouxu {
		color: #fbb501;
		font-family: Alibaba PuHuiTi 2;
		font-size: 24rpx;
		font-weight: 400;
		margin-top: 32rpx;
	}

	.wx_img {
		width: 300rpx;
		height: 300rpx;
		background-image: url('https://bucketoss10086.oss-cn-beijing.aliyuncs.com/miniprogram/up_border.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		position: relative;
		margin-top: 30rpx;
	}

	.wx_img_add {
		width: 80rpx;
		height: 80rpx;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
	}

	.wx_img_ma {
		width: 300rpx;
		height: 300rpx;
		border-radius: 20rpx;
	}

	.apli_input {
		width: 100%;
		height: 78rpx;
		padding-left: 30rpx;
		box-sizing: border-box;
		font-size: 32rpx;
		font-weight: 400;
		background: #F4F4F4;
		border-radius: 40rpx;
		margin-top: 30rpx;
	}
</style>